﻿using System;
using System.Collections.Generic;
using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;


namespace TestDxfDocument
{
    class ReamersForIndexableInserts
    {
        public static void CylindricalReamer312(Dictionary<string, Object> data)  //圆柱铰刀 
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            //作图
            //参数
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && soal < 67)
            {
                scale = 4.0;
            }
            else if (scale == 0 && soal < 90)
            {
                scale = 3.0;
            }
            else if (scale == 0 && soal < 134)
            {
                scale = 2.0;
            }
            else if (scale == 0 && soal < 178)
            {
                scale = 1.5;
            }
            else if (scale == 0 && soal < 268)
            {
                scale = 1.0;
            }
            else if (scale == 0 && soal < 357)
            {
                scale = 0.75;
            }
            else if (scale == 0)
            {
                scale = 0.5;
            }
            double pi = Math.PI;
            double dmm = Convert.ToDouble(data["dmm"]) * scale; //Convert.ToDouble(data["dmm"]);
            double oal = Convert.ToDouble(data["oal"]) * scale; //Convert.ToDouble(data["oal"]);
            double ls = Convert.ToDouble(data["ls"]) * scale; //Convert.ToDouble(data["ls"]);
            double dc = Convert.ToDouble(data["dc"]) * scale; //Convert.ToDouble(data["dc"]);
            double apmx = Convert.ToDouble(data["apmx"]) * scale; //Convert.ToDouble(data["apmx"]);
            double plgl = Convert.ToDouble(data["plgl"]) * scale; //Convert.ToDouble(data["plgl"]);
            //double lu = 46 * scale; //Convert.ToDouble(data["lu"]);
            double l = Convert.ToDouble(data["l"]) * scale; //Convert.ToDouble(data["l"]);
            //double lpr = 100 * scale; //Convert.ToDouble(data["lpr"]);
            double lf = Convert.ToDouble(data["lf"]) * scale; //Convert.ToDouble(data["lf"]);
            double plgang = Convert.ToDouble(data["plgang"]) * pi / 180; //Convert.ToDouble(data["plgang"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);
            //坐标
            Vector2 p00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p01 = fun.Polar(p00, 0.5 * pi, oal);  // 基准点 角度（弧度制） 距离
            Vector2 p0 = new Vector2(p01.X + dmm / 2 - plgl * Math.Sin(plgang), p01.Y);
            Vector2 p1 = new Vector2(p01.X + dmm / 2, p0.Y - plgl * Math.Cos(plgang));
            Vector2 p2 = new Vector2(p1.X, p1.Y - ls);
            Vector2 p3 = fun.Polar(p2, pi + plgang, plgl);
            Vector2 p4 = new Vector2(p3.X, p3.Y - (oal - ls - l - 2 * plgl * Math.Cos(plgang)));
            Vector2 p5 = new Vector2(p4.X + plgl * Math.Sin(plgang), p4.Y - plgl * Math.Cos(plgang));
            Vector2 p6 = new Vector2(p5.X, p5.Y - l + apmx);
            Vector2 p7 = new Vector2(p6.X, p00.Y + plgl);
            Vector2 p8 = new Vector2(p7.X - plgl * Math.Cos(plgang), p00.Y);
            Vector2 p9 = new Vector2(-p8.X, p8.Y);
            Vector2 p10 = new Vector2(-p7.X, p7.Y);
            Vector2 p11 = new Vector2(-p5.X, p5.Y);
            Vector2 p12 = new Vector2(-p4.X, p4.Y);
            Vector2 p13 = new Vector2(-p3.X, p3.Y);
            Vector2 p14 = new Vector2(-p2.X, p2.Y);
            Vector2 p15 = new Vector2(-p1.X, p1.Y);
            Vector2 p16 = new Vector2(-p0.X, p0.Y);
            //Vector2 p20 = new Vector2(p2.X, p00.Y + lpr);
            //Vector2 p21 = new Vector2(p3.X, p00.Y + lu);
            Vector2 p22 = new Vector2(p00.X, p00.Y + 0.7 * l);
            Vector2 p23 = new Vector2(p10.X, p22.Y);
            Vector2 p31 = new Vector2(p8.X, p6.Y);
            Vector2 p32 = new Vector2(p31.X - plgl / Math.Tan(plgang), p6.Y);
            Vector2 p34 = new Vector2(p32.X, p32.Y - 0.5 * p6.Y);
            Vector2 p33 = new Vector2(p32.X, p00.Y);
            Vector2 p35 = new Vector2(p31.X, p31.Y - p6.Y * 0.25);
            Vector2 p36 = new Vector2(p31.X, p31.Y - p6.Y * 0.75);
            Vector2 p37 = new Vector2(p31.X + 0.2 * plgl / Math.Tan(plgang), p36.Y);
            Vector2 p38 = new Vector2(p31.X + 0.2 * plgl / Math.Tan(plgang), p35.Y);
            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p0));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p10));
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p13));
            poly.Vertexes.Add(new LwPolylineVertex(p14));
            poly.Vertexes.Add(new LwPolylineVertex(p15));
            poly.Vertexes.Add(new LwPolylineVertex(p16));
            poly.Vertexes.Add(new LwPolylineVertex(p0));
            fun.PolyFill(dxf, poly, 0.3, contour);
            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p31));
            poly2.Vertexes.Add(new LwPolylineVertex(p35));
            poly2.Vertexes[1].Bulge = Math.Tan(pi / 4);
            poly2.Vertexes.Add(new LwPolylineVertex(p36));
            poly2.Vertexes.Add(new LwPolylineVertex(p8));
            poly2.Vertexes.Add(new LwPolylineVertex(p33));
            poly2.Vertexes.Add(new LwPolylineVertex(p34));
            poly2.Vertexes.Add(new LwPolylineVertex(p32));
            poly2.Vertexes.Add(new LwPolylineVertex(p31));
            fun.PolyFill(dxf, poly2, 0.3, contour);
            //线段
            Vector2[] dotline1 = { fun.Polar(p01, pi / 2, 2), fun.Polar(p00, 1.5 * pi, 2) };
            fun.drawPlinetype(dxf, dotline1, 0.15, center, Linetype.Center);
            Vector2[] xiline1 = { p1, p15 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, contour);
            Vector2[] xiline2 = { p2, p14 };
            fun.drawPlineOfw(dxf, xiline2, 0.3, contour);
            Vector2[] xiline3 = { p3, p13 };
            fun.drawPlineOfw(dxf, xiline3, 0.3, contour);
            Vector2[] xiline4 = { p4, p12 };
            fun.drawPlineOfw(dxf, xiline4, 0.3, contour);
            Vector2[] xiline5 = { p5, p11 };
            fun.drawPlineOfw(dxf, xiline5, 0.3, contour);
            Vector2[] xiline6 = { p10, p23 };
            fun.drawPlineOfw(dxf, xiline6, 1, contour);
            Vector2[] xiline7 = { p22, p00 };
            fun.drawPlineOfw(dxf, xiline7, 1, contour);
            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p6));
            poly3.Vertexes.Add(new LwPolylineVertex(p7));
            poly3.Vertexes.Add(new LwPolylineVertex(p8));
            poly3.Vertexes.Add(new LwPolylineVertex(p36));
            poly3.Vertexes.Add(new LwPolylineVertex(p37));
            poly3.Vertexes.Add(new LwPolylineVertex(p38));
            poly3.Vertexes.Add(new LwPolylineVertex(p35));
            poly3.Vertexes.Add(new LwPolylineVertex(p31));
            poly3.Vertexes.Add(new LwPolylineVertex(p6));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;
            //填充
            String[] type = new String[100];
            Line[] line = new Line[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, type, numst, 1, 1, line, hatching);  //  dxf type numst 填充线段的间距 填充线段的角度 line 图层颜色
            fun.PolyFill(dxf, poly3, 0.3, contour);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(p8, p0), offset * 5 + p7.X - (p8.X + p0.X) / 2, 270, dimensionStyle);
            dim1.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim1);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(p1, p15), offset + p0.Y - p1.Y, 0, dimensionStyle);
            dim3.UserText = "DMM = " + Math.Round(dmm / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸5
            LinearDimension dim5 = new LinearDimension(new Line(p5, p8), offset * 4 + (p5.X - p8.X) / 2, 270, dimensionStyle);
            dim5.UserText = "L = " + Math.Round(l / scale, 2);
            dxf.AddEntity(dim5);
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(p7, p10), offset * 2.5, 180, dimensionStyle);
            dim6.UserText = "DC = " + Math.Round(dc / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            LinearDimension dim7 = new LinearDimension(new Line(p14, p16), offset, 90, dimensionStyle);
            dim7.UserText = "LS = " + Math.Round(ls / scale, 2);
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(p16, p10), offset * 2.5, 90, dimensionStyle);
            dim8.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim10 = new LinearDimension(new Line(p8, p6), offset * 3, 270, dimensionStyle);
            dim10.UserText = "APMX = " + Math.Round(apmx / scale, 2);
            dxf.AddEntity(dim10);
            //尺寸10
            LinearDimension dim11 = new LinearDimension(new Line(p8, p7), offset * 1.5, 270, dimensionStyle);
            dim11.UserText = "PLGL = " + Math.Round(plgl / scale, 2);
            dxf.AddEntity(dim11);
            //尺寸11
            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p9, p10), new Line(p00, p01), offset * 4, dimensionStyle);
            angdim1.UserText = "PLGANG = " + Math.Round(plgang / (pi / 180), 2) + "°";
            dxf.AddEntity(angdim1);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 + oal / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void TaperedReamer312(Dictionary<string, Object> data)  //锥度铰刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            //作图
            //参数
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && soal < 67)
            {
                scale = 4.0;
            }
            else if (scale == 0 && soal < 90)
            {
                scale = 3.0;
            }
            else if (scale == 0 && soal < 134)
            {
                scale = 2.0;
            }
            else if (scale == 0 && soal < 178)
            {
                scale = 1.5;
            }
            else if (scale == 0 && soal < 268)
            {
                scale = 1.0;
            }
            else if (scale == 0 && soal < 357)
            {
                scale = 0.75;
            }
            else if (scale == 0)
            {
                scale = 0.5;
            }
            double pi = Math.PI;
            double dmm = Convert.ToDouble(data["dmm"]) * scale; //Convert.ToDouble(data["dmm"]);
            double oal = Convert.ToDouble(data["oal"]) * scale; //Convert.ToDouble(data["oal"]);
            double ls = Convert.ToDouble(data["ls"]) * scale; //Convert.ToDouble(data["ls"]);
            double dcn = Convert.ToDouble(data["dcn"]) * scale; //Convert.ToDouble(data["dcn"]);
            double ldc = Convert.ToDouble(data["ldc"]) * scale; //Convert.ToDouble(data["ldc"]);
            double lf = oal - ldc; //Convert.ToDouble(data["lf"]);
            double ta = Convert.ToDouble(data["ta"]); //Convert.ToDouble(data["sig"]);
            double apmx = Convert.ToDouble(data["apmx"]) * scale;//Convert.ToDouble(data["apmx"]);
            double dtan = dcn - 2 * ldc * Math.Tan(ta * pi / 180 / 2);
            double dtax = dtan + 2 * apmx * Math.Tan(ta * pi / 180 / 2);
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);
            //坐标
            Vector2 p01 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p00 = fun.Polar(p01, 0.5 * pi, oal);  // 基准点 角度（弧度制） 距离
            Vector2 p6 = fun.Polar(p01, 0, dtan / 2);
            Vector2 p7 = fun.Polar(p01, pi, dtan / 2);
            Vector2 p5 = new Vector2(dtax / 2, apmx);
            Vector2 p8 = fun.Polar(p5, pi, dtax);
            Vector2 p4 = fun.Polar(p5, pi - pi / 6, dtax * 0.2);
            Vector2 p9 = fun.Polar(p8, pi / 6, dtax * 0.2);
            Vector2 p3 = new Vector2(p4.X, oal - ls - 0.1 * dmm);
            Vector2 p10 = new Vector2(p9.X, oal - ls - 0.1 * dmm);
            Vector2 p2 = new Vector2(dmm / 2, oal - ls);
            Vector2 p11 = fun.Polar(p2, pi, dmm);
            Vector2 p1 = new Vector2(dmm / 2, oal - 0.5);
            Vector2 p12 = fun.Polar(p1, pi, dmm);
            Vector2 p0 = new Vector2(p1.X - 0.5, oal);//fun.Polar(p1, 0.75 * pi, 0.1 * dmm * 1.414);
            Vector2 p13 = new Vector2(-p0.X, p0.Y);//fun.Polar(p12, 0.25 * pi, 0.1 * dmm * 1.414);
            Vector2 p85 = new Vector2(-dtax / 4, p8.Y);
            Vector2 p75 = new Vector2(-dtan / 4, p7.Y);
            Vector2 p91 = new Vector2(p01.X + dtax / 8, p5.Y);
            Vector2 p92 = new Vector2(p01.X, p01.Y);
            //Vector2 p20 = new Vector2(dmm / 2, lpr);
            Vector2 p30 = new Vector2(dcn / 2, p01.Y + ldc);
            Vector2 p31 = new Vector2(-p30.X, p30.Y);
            Vector2 p63 = new Vector2(p6.X - (p5.X - p6.X), p01.Y);
            Vector2 p62 = new Vector2(p6.X - 10 * (p5.X - p6.X) / 11, p01.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17 * 2);
            Vector2 p61 = new Vector2(p6.X - 9 * (p5.X - p6.X) / 11, p62.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17);
            Vector2 p60 = new Vector2(p6.X - 8 * (p5.X - p6.X) / 11, p61.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17 * 2);
            Vector2 p59 = new Vector2(p6.X - 7 * (p5.X - p6.X) / 11, p60.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17);
            Vector2 p58 = new Vector2(p6.X - 6 * (p5.X - p6.X) / 11, p59.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17 * 2);
            Vector2 p57 = new Vector2(p6.X - 5 * (p5.X - p6.X) / 11, p58.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17);
            Vector2 p56 = new Vector2(p6.X - 4 * (p5.X - p6.X) / 11, p57.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17 * 2);
            Vector2 p55 = new Vector2(p6.X - 3 * (p5.X - p6.X) / 11, p56.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17);
            Vector2 p54 = new Vector2(p6.X - 2 * (p5.X - p6.X) / 11, p55.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17 * 2);
            Vector2 p53 = new Vector2(p6.X - 1 * (p5.X - p6.X) / 11, p54.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17);
            Vector2 p52 = new Vector2(p6.X - 0 * (p5.X - p6.X) / 11, p53.Y + (apmx + (p5.X - p6.X) / 8 * Math.Sin(ta / 2)) / 17 * 2);
            Vector2 p73 = new Vector2(p6.X + (p5.X - p6.X) / 11, p01.Y + apmx / 17 * 2);
            Vector2 p72 = new Vector2(p6.X + 2 * (p5.X - p6.X) / 11, p73.Y + apmx / 17);
            Vector2 p71 = new Vector2(p6.X + 3 * (p5.X - p6.X) / 11, p72.Y + apmx / 17 * 2);
            Vector2 p70 = new Vector2(p6.X + 4 * (p5.X - p6.X) / 11, p71.Y + apmx / 17);
            Vector2 p69 = new Vector2(p6.X + 5 * (p5.X - p6.X) / 11, p70.Y + apmx / 17 * 2);
            Vector2 p68 = new Vector2(p6.X + 6 * (p5.X - p6.X) / 11, p69.Y + apmx / 17);
            Vector2 p67 = new Vector2(p6.X + 7 * (p5.X - p6.X) / 11, p68.Y + apmx / 17 * 2);
            Vector2 p66 = new Vector2(p6.X + 8 * (p5.X - p6.X) / 11, p67.Y + apmx / 17);
            Vector2 p65 = new Vector2(p6.X + 9 * (p5.X - p6.X) / 11, p66.Y + apmx / 17 * 2);
            Vector2 p64 = new Vector2(p6.X + 10 * (p5.X - p6.X) / 11, p65.Y + apmx / 17);
            //线段
            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p13));
            poly.Vertexes.Add(new LwPolylineVertex(p0));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p10));
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p13));
            fun.PolyFill(dxf, poly, 0.3, contour);
            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p5));
            poly2.Vertexes.Add(new LwPolylineVertex(p52));
            //poly2.Vertexes.Add(new LwPolylineVertex(p53));
            //poly2.Vertexes.Add(new LwPolylineVertex(p64));
            //poly2.Vertexes.Add(new LwPolylineVertex(p53));
            //poly2.Vertexes[4].Bulge = Math.Tan(pi / 4);
            //poly2.Vertexes.Add(new LwPolylineVertex(p54));
            //poly2.Vertexes.Add(new LwPolylineVertex(p65));
            //poly2.Vertexes.Add(new LwPolylineVertex(p54));
            //poly2.Vertexes.Add(new LwPolylineVertex(p55));
            //poly2.Vertexes.Add(new LwPolylineVertex(p66));
            //poly2.Vertexes.Add(new LwPolylineVertex(p55));
            //poly2.Vertexes[10].Bulge = Math.Tan(pi / 4);
            //poly2.Vertexes.Add(new LwPolylineVertex(p56));
            //poly2.Vertexes.Add(new LwPolylineVertex(p67));
            //poly2.Vertexes.Add(new LwPolylineVertex(p56));
            //poly2.Vertexes.Add(new LwPolylineVertex(p57));
            //poly2.Vertexes.Add(new LwPolylineVertex(p68));
            //poly2.Vertexes.Add(new LwPolylineVertex(p57));
            //poly2.Vertexes[16].Bulge = Math.Tan(pi / 4);
            //poly2.Vertexes.Add(new LwPolylineVertex(p58));
            //poly2.Vertexes.Add(new LwPolylineVertex(p69));
            //poly2.Vertexes.Add(new LwPolylineVertex(p58));
            //poly2.Vertexes.Add(new LwPolylineVertex(p59));
            //poly2.Vertexes.Add(new LwPolylineVertex(p70));
            //poly2.Vertexes.Add(new LwPolylineVertex(p59));
            //poly2.Vertexes[22].Bulge = Math.Tan(pi / 4);
            //poly2.Vertexes.Add(new LwPolylineVertex(p60));
            //poly2.Vertexes.Add(new LwPolylineVertex(p71));
            //poly2.Vertexes.Add(new LwPolylineVertex(p60));
            //poly2.Vertexes.Add(new LwPolylineVertex(p61));
            //poly2.Vertexes.Add(new LwPolylineVertex(p72));
            //poly2.Vertexes.Add(new LwPolylineVertex(p61));
            //poly2.Vertexes[28].Bulge = Math.Tan(pi / 4);
            //poly2.Vertexes.Add(new LwPolylineVertex(p62));
            //poly2.Vertexes.Add(new LwPolylineVertex(p73));
            //poly2.Vertexes.Add(new LwPolylineVertex(p62));
            poly2.Vertexes.Add(new LwPolylineVertex(p63));
            fun.PolyFill(dxf, poly2, 0.3, contour);
            Vector2[] dotline1 = { fun.Polar(p00, pi / 2, 2), fun.Polar(p01, 1.5 * pi, 2) };
            fun.drawPlinetype(dxf, dotline1, 0.15, center, Linetype.Center);
            Vector2[] xiline1 = { p12, p1, p2, p11, p10, p3, p4, p9, p8, p91, p4 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, contour);
            Vector2[] xiline4 = { p92, p91 };
            fun.drawPlineOfw(dxf, xiline4, 0.3, contour);
            Vector2[] xiline2 = { p7, p8 };
            fun.drawPlineOfw(dxf, xiline2, 1, contour);
            Vector2[] xiline3 = { p85, p75 };
            fun.drawPlineOfw(dxf, xiline3, 1, contour);
            Vector2[] xiline5 = { p6, p5 };
            fun.drawPlineOfw(dxf, xiline5, 1, contour);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(p6, p0), offset * 3 + p5.X - (p0.X + p6.X) / 2, 270, dimensionStyle);
            dim1.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim1);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(p1, p12), offset, 0, dimensionStyle);
            dim3.UserText = "DMM = " + Math.Round(dmm / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(p6, p30), offset + p5.X - (p6.X + p30.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LDC = " + Math.Round(ldc / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            LinearDimension dim5 = new LinearDimension(new Line(p5, p6), offset * 2 + (p5.X - p6.X) / 2, 270, dimensionStyle);
            dim5.UserText = "APMX = " + Math.Round(apmx / scale, 2);
            dxf.AddEntity(dim5);
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(p6, p7), -offset, 0, dimensionStyle);
            dim6.UserText = "DTAN = " + Math.Round(dtan / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            LinearDimension dim7 = new LinearDimension(new Line(p30, p31), -offset * 2 - ldc, 0, dimensionStyle);
            dim7.UserText = "DCN = " + Math.Round(dcn / scale, 2);
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(p31, p13), -offset - (p31.X - p13.X) / 2, 270, dimensionStyle);
            dim8.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(p5, p8), offset, 0, dimensionStyle);
            dim9.UserText = "DTAX = " + Math.Round(dtax / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p7, p8), new Line(p6, p5), offset*2.5 + apmx + dtan / 2 / Math.Tan(ta * pi / 180 / 2), dimensionStyle);
            angdim1.UserText = "TA = " + Math.Round(ta, 2) + "°";
            dxf.AddEntity(angdim1);
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(p0, p2), offset + (p2.X - p0.X) / 2, 270, dimensionStyle);
            dim11.UserText = "LS = " + Math.Round(ls / scale, 2);
            dxf.AddEntity(dim11);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 + oal / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void SteppedReamer312(Dictionary<string, Object> data)  //阶梯铰刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            //作图
            //参数
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && soal < 67)
            {
                scale = 4.0;
            }
            else if (scale == 0 && soal < 90)
            {
                scale = 3.0;
            }
            else if (scale == 0 && soal < 134)
            {
                scale = 2.0;
            }
            else if (scale == 0 && soal < 178)
            {
                scale = 1.5;
            }
            else if (scale == 0 && soal < 268)
            {
                scale = 1.0;
            }
            else if (scale == 0 && soal < 357)
            {
                scale = 0.75;
            }
            else if (scale == 0)
            {
                scale = 0.5;
            }
            double pi = Math.PI;
            double dmm = Convert.ToDouble(data["dmm"]) * scale; //Convert.ToDouble(data["dmm"]);
            double oal = Convert.ToDouble(data["oal"]) * scale; //Convert.ToDouble(data["oal"]);
            double ls = Convert.ToDouble(data["ls"]) * scale; //Convert.ToDouble(data["ls"]);
            double lpr = oal - ls; //Convert.ToDouble(data["lpr"]);
            double lu = Convert.ToDouble(data["lu"]) * scale; //Convert.ToDouble(data["lu"]);
            double sdn_4 = Convert.ToDouble(data["sdn4"]) * scale; //Convert.ToDouble(data["sd_x"]);
            double plgl = Convert.ToDouble(data["plgl"]) * scale; //Convert.ToDouble(data["plgl"]);
            double plgang = Convert.ToDouble(data["plgang"]) * pi / 180; //Convert.ToDouble(data["plgang"]);
            double dc_x = Convert.ToDouble(data["dc4"]) * scale; //Convert.ToDouble(data["dc_x"]);
            double dc_1 = Convert.ToDouble(data["dc1"]) * scale; //Convert.ToDouble(data["dc_1"]);
            double sdl_1 = Convert.ToDouble(data["sdl1"]) * scale; //Convert.ToDouble(data["sdl_1"]);
            double lf = oal - plgl; //Convert.ToDouble(data["lf"]);
            double sta_4 = Convert.ToDouble(data["sta4"]) * pi / 180; //Convert.ToDouble(data["sta_x"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);
            //坐标
            Vector2 p00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p01 = fun.Polar(p00, 0.5 * pi, oal);  // 基准点 角度（弧度制） 距离
            Vector2 p11 = fun.Polar(p00, pi, dc_1 / 2 - plgl * Math.Tan(plgang));
            Vector2 p51 = fun.Polar(p00, 0, dc_1 / 2 - plgl * Math.Tan(plgang));
            Vector2 p120 = fun.Polar(p00, pi, dc_1 / 2);
            Vector2 p520 = fun.Polar(p00, 0, dc_1 / 2);
            Vector2 p12 = new Vector2(p120.X, p120.Y + plgl);
            Vector2 p52 = new Vector2(p520.X, p520.Y + plgl);
            Vector2 p13 = new Vector2(p12.X, p12.Y + 0.75 * sdl_1);
            Vector2 p53 = new Vector2(p52.X, p13.Y);
            Vector2 p14 = fun.Polar(p13, 0.25 * pi, 0.1 * sdl_1 * 1.414);
            Vector2 p54 = fun.Polar(p53, 0.75 * pi, 0.1 * sdl_1 * 1.414);
            Vector2 p15 = new Vector2(p14.X, p14.Y + 0.16 * sdl_1);
            Vector2 p55 = new Vector2(p54.X, p54.Y + 0.16 * sdl_1);
            Vector2 p16 = fun.Polar(p15, 0.75 * pi, 0.1 * sdn_4 * 1);
            Vector2 p56 = fun.Polar(p55, 0.25 * pi, 0.1 * sdn_4 * 1);
            Vector2 p17 = new Vector2(p16.X, p16.Y + (0.7 * sdn_4 - sdl_1 - plgl) / 2);
            Vector2 p57 = new Vector2(p56.X, p17.Y);
            Vector2 p200 = fun.Polar(p00, pi, dc_x / 2);
            Vector2 p600 = fun.Polar(p00, 0, dc_x / 2);
            Vector2 p20 = new Vector2(p200.X, p200.Y + sdn_4);
            Vector2 p60 = new Vector2(p600.X, p600.Y + sdn_4);
            Vector2 p19 = fun.Polar(p20, 1.5 * pi + sta_4 / 2, 0.1 * sdn_4 * 1);
            Vector2 p59 = fun.Polar(p60, 1.5 * pi - sta_4 / 2, 0.1 * sdn_4 * 1);
            Vector2 p18 = new Vector2(p19.X, p19.Y - (0.7 * sdn_4 - sdl_1 - plgl) / 2);
            Vector2 p58 = new Vector2(p59.X, p18.Y);
            Vector2 p21 = new Vector2(p20.X, p60.Y - sdn_4);
            Vector2 p61 = new Vector2(p60.X, p60.Y - sdn_4);
            Vector2 p22 = fun.Polar(p21, 0.25 * pi, 0.06 * dc_x * 1.414);
            Vector2 p62 = fun.Polar(p61, 0.75 * pi, 0.06 * dc_x * 1.414);
            Vector2 p23 = new Vector2(p22.X, p22.Y + 0.05 * lpr);
            Vector2 p63 = new Vector2(p62.X, p62.Y + 0.05 * lpr);
            Vector2 p24 = fun.Polar(p23, 0.75 * pi, 0.06 * dc_x * 1.414);
            Vector2 p64 = fun.Polar(p63, 0.25 * pi, 0.06 * dc_x * 1.414);
            Vector2 p25 = new Vector2(p24.X, lpr);
            Vector2 p65 = new Vector2(p64.X, p25.Y);
            Vector2 p255 = new Vector2(p25.X - 2, p25.Y + 2);
            Vector2 p655 = new Vector2(p65.X + 2, p65.Y + 2);
            Vector2 p26 = new Vector2(p255.X - 2, p255.Y);
            Vector2 p66 = new Vector2(p655.X + 2, p655.Y);
            Vector2 p27 = new Vector2(p26.X, p26.Y + lpr - lu - 2);
            Vector2 p67 = new Vector2(p66.X, p66.Y + lpr - lu - 2);
            Vector2 p290 = fun.Polar(p00, pi, dmm / 2);
            Vector2 p690 = fun.Polar(p00, 0, dmm / 2);
            Vector2 p29 = new Vector2(p290.X, p27.Y + 1);
            Vector2 p69 = new Vector2(p690.X, p29.Y);
            Vector2 p28 = fun.Polar(p29, 1.75 * pi, 1 * 1.414);
            Vector2 p68 = fun.Polar(p69, 1.25 * pi, 1 * 1.414);
            Vector2 p36 = new Vector2(p67.X - 0.25 * dc_x, p27.Y);
            Vector2 p35 = new Vector2(p27.X + 0.25 * dc_x, p67.Y);
            Vector2 p34 = new Vector2(p35.X, p255.Y);
            Vector2 p37 = new Vector2(p36.X, p655.Y);
            Vector2 p30 = new Vector2(p29.X, p29.Y + ls / 3);
            Vector2 p70 = new Vector2(p69.X, p69.Y + ls / 3);
            Vector2 p31 = new Vector2(p30.X, p30.Y + ls / 3);
            Vector2 p71 = new Vector2(p70.X, p70.Y + ls / 3);
            Vector2 p32 = new Vector2(p31.X, p31.Y + ls / 3);
            Vector2 p72 = new Vector2(p71.X, p71.Y + ls / 3);
            Vector2 p33 = fun.Polar(p32, 0.25 * pi, 1 * 1.414);
            Vector2 p73 = fun.Polar(p72, 0.75 * pi, 1 * 1.414);
            Vector2 p84 = new Vector2(p00.X + dc_1 * 0.125, p24.Y);
            Vector2 p83 = new Vector2(p00.X + dc_1 * 0.125, p23.Y);
            Vector2 p82 = new Vector2(p00.X + dc_1 * 0.125, p22.Y);
            Vector2 p81 = new Vector2(p00.X + dc_1 * 0.125, p21.Y);
            Vector2 p80 = new Vector2(p00.X + dc_1 * 0.125, p20.Y);
            Vector2 p79 = new Vector2(p00.X + dc_1 * 0.125, p19.Y);
            Vector2 p78 = new Vector2(p00.X + dc_1 * 0.125, p18.Y);
            Vector2 p77 = new Vector2(p00.X + dc_1 * 0.125, p17.Y);
            Vector2 p76 = new Vector2(p00.X + dc_1 * 0.125, p16.Y);
            Vector2 p75 = new Vector2(p00.X + dc_1 * 0.125, p15.Y);
            Vector2 p74 = new Vector2(p00.X + dc_1 * 0.125, p14.Y);
            Vector2 p743 = new Vector2(p00.X + dc_1 * 0.125, p13.Y);
            Vector2 p742 = new Vector2(p00.X + dc_1 * 0.125, p12.Y);
            Vector2 p741 = new Vector2(p00.X + dc_1 * 0.125, p11.Y);
            Vector2 p740 = new Vector2(p00.X + dc_1 * 0.125, p00.Y);
            Vector2 p111 = new Vector2(p01.X, p25.Y - 0.05 * sdn_4);
            Vector2 p112 = new Vector2(p01.X, p20.Y);
            Vector2 p113 = new Vector2(p01.X, p16.Y);
            Vector2 p114 = new Vector2(p01.X, p17.Y);
            Vector2 p115 = new Vector2(p01.X, p12.Y);
            Vector2 p116 = new Vector2(p01.X, p13.Y);
            Vector2 p251 = new Vector2(p25.X, p111.Y);
            Vector2 p651 = new Vector2(p65.X, p251.Y);
            Vector2 p108 = new Vector2(p65.X - 0.05 * sdn_4, p251.Y);
            Vector2 p110 = new Vector2(p65.X - 0.06 * sdn_4, p19.Y);
            Vector2 p109 = new Vector2(p110.X, p108.Y - 0.01 * sdn_4);
            Vector2 p118 = new Vector2(p57.X - 0.04 * sdn_4, p57.Y + 0.04 * sdn_4);
            Vector2 p117 = new Vector2(p118.X + 0.089 * sdn_4, p118.Y + 0.089 * sdn_4);
            Vector2 p1171 = new Vector2(p58.X, p58.Y + 0.02 * sdn_4);
            Vector2 p1191 = new Vector2(p56.X, p56.Y + 0.04 * sdn_4);
            Vector2 p119 = new Vector2(p1191.X - 0.075 * sdn_4, p1191.Y);
            Vector2 p220 = new Vector2(p119.X - 0.01 * sdn_4, p119.Y - 0.01 * sdn_4);
            Vector2 p121 = new Vector2(p220.X, p55.Y);
            Vector2 p122 = new Vector2(p121.X, p14.Y);
            Vector2 p123 = new Vector2(p51.X + 0.3 * plgl, p53.Y);
            Vector2 p124 = new Vector2(p51.X, p53.Y - 0.3 * plgl);
            //线段
            Vector2[] Line1 = { p73, p72 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { p72, p71 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line3 = { p71, p70 };
            fun.drawBLine(dxf, Line3, 0.3, contour);
            Vector2[] Line4 = { p70, p69 };
            fun.drawBLine(dxf, Line4, 0.3, contour);
            Vector2[] Line5 = { p69, p68 };
            fun.drawBLine(dxf, Line5, 0.3, contour);
            Vector2[] Line6 = { p68, p67 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line7 = { p67, p66 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { p66, p655 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line9 = { p655, p65 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line10 = { p65, p60 };
            fun.drawBLine(dxf, Line10, 0.3, contour);
            Vector2[] Line11 = { p60, p59 };
            fun.drawBLine(dxf, Line11, 0.3, contour);
            Vector2[] Line12 = { p59, p58 };
            fun.drawBLine(dxf, Line12, 0.3, contour);
            Vector2[] Line13 = { p58, p57 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line14 = { p57, p56 };
            fun.drawBLine(dxf, Line14, 0.3, contour);
            Vector2[] Line15 = { p56, p55 };
            fun.drawBLine(dxf, Line15, 0.3, contour);
            Vector2[] Line16 = { p55, p54 };
            fun.drawBLine(dxf, Line16, 0.3, contour);
            Vector2[] Line17 = { p54, p53 };
            fun.drawBLine(dxf, Line17, 0.3, contour);
            Vector2[] Line18 = { p53, p52 };
            fun.drawBLine(dxf, Line18, 0.3, contour);
            Vector2[] Line19 = { p52, p51 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { p51, p11 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            Vector2[] Line21 = { p11, p12 };
            fun.drawBLine(dxf, Line21, 0.3, contour);
            Vector2[] Line22 = { p12, p13 };
            fun.drawBLine(dxf, Line22, 0.3, contour);
            Vector2[] Line23 = { p13, p14 };
            fun.drawBLine(dxf, Line23, 0.3, contour);
            Vector2[] Line24 = { p14, p15 };
            fun.drawBLine(dxf, Line24, 0.3, contour);
            Vector2[] Line25 = { p15, p16 };
            fun.drawBLine(dxf, Line25, 0.3, contour);
            Vector2[] Line26 = { p16, p17 };
            fun.drawBLine(dxf, Line26, 0.3, contour);
            Vector2[] Line27 = { p17, p18 };
            fun.drawBLine(dxf, Line27, 0.3, contour);
            Vector2[] Line28 = { p18, p19 };
            fun.drawBLine(dxf, Line28, 0.3, contour);
            Vector2[] Line29 = { p19, p20 };
            fun.drawBLine(dxf, Line29, 0.3, contour);
            Vector2[] Line30 = { p20, p25 };
            fun.drawBLine(dxf, Line30, 0.3, contour);
            Vector2[] Line31 = { p25, p255 };
            fun.drawBLine(dxf, Line31, 0.3, contour);
            Vector2[] Line32 = { p255, p26 };
            fun.drawBLine(dxf, Line32, 0.3, contour);
            Vector2[] Line33 = { p26, p27 };
            fun.drawBLine(dxf, Line33, 0.3, contour);
            Vector2[] Line34 = { p27, p28 };
            fun.drawBLine(dxf, Line34, 0.3, contour);
            Vector2[] Line35 = { p28, p29 };
            fun.drawBLine(dxf, Line35, 0.3, contour);
            Vector2[] Line36 = { p29, p30 };
            fun.drawBLine(dxf, Line36, 0.3, contour);
            Vector2[] Line37 = { p30, p31 };
            fun.drawBLine(dxf, Line37, 0.3, contour);
            Vector2[] Line38 = { p31, p32 };
            fun.drawBLine(dxf, Line38, 0.3, contour);
            Vector2[] Line39 = { p32, p33 };
            fun.drawBLine(dxf, Line39, 0.3, contour);
            Vector2[] Line40 = { p33, p73 };
            fun.drawBLine(dxf, Line40, 0.3, contour);
            Vector2[] dotline1 = { fun.Polar(p01, pi / 2, 4), fun.Polar(p00, 1.5 * pi, 4) };
            fun.drawPlinetype(dxf, dotline1, 0.15, center, Linetype.Center);
            Vector2[] xiline1 = { p32, p72 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, contour);
            Vector2[] xiline2 = { p29, p69 };
            fun.drawPlineOfw(dxf, xiline2, 0.3, contour);
            Vector2[] xiline3 = { p35, p36, p34, p37, p35, };
            fun.drawPlineOfw(dxf, xiline3, 0.15, contour);
            Vector2[] xiline4 = { p34, p35 };
            fun.drawPlineOfw(dxf, xiline4, 0.3, contour);
            Vector2[] xiline5 = { p36, p37 };
            fun.drawPlineOfw(dxf, xiline5, 0.3, contour);
            Vector2[] xiline6 = { p27, p67, p66, p26 };
            fun.drawPlineOfw(dxf, xiline6, 0.3, contour);
            Vector2[] xiline8 = { p11, p741 };
            fun.drawPlineOfw(dxf, xiline8, 0.3, contour);
            Vector2[] xiline9 = { p12, p742 };
            fun.drawPlineOfw(dxf, xiline9, 0.3, contour);
            Vector2[] xiline7 = { p13, p743 };
            fun.drawPlineOfw(dxf, xiline7, 0.3, contour);
            Vector2[] xiline10 = { p14, p74 };
            fun.drawPlineOfw(dxf, xiline10, 0.3, contour);
            Vector2[] xiline11 = { p15, p75 };
            fun.drawPlineOfw(dxf, xiline11, 0.3, contour);
            Vector2[] xiline12 = { p16, p76 };
            fun.drawPlineOfw(dxf, xiline12, 0.3, contour);
            Vector2[] xiline13 = { p17, p77 };
            fun.drawPlineOfw(dxf, xiline13, 0.3, contour);
            Vector2[] xiline14 = { p18, p78 };
            fun.drawPlineOfw(dxf, xiline14, 0.3, contour);
            Vector2[] xiline15 = { p19, p79 };
            fun.drawPlineOfw(dxf, xiline15, 0.3, contour);
            Vector2[] xiline16 = { p20, p80 };
            fun.drawPlineOfw(dxf, xiline16, 0.3, contour);
            Vector2[] xiline17 = { p251, p20, p19 };
            fun.drawPlineOfw(dxf, xiline17, 1, contour);
            Vector2[] xiline18 = { p17, p16, p15 };
            fun.drawPlineOfw(dxf, xiline18, 1, contour);
            Vector2[] xiline19 = { p13, p12, p11 };
            fun.drawPlineOfw(dxf, xiline19, 1, contour);
            Vector2[] xiline199 = { p111, p112 };
            fun.drawPlineOfw(dxf, xiline199, 1, contour);
            Vector2[] xiline20 = { p113, p114 };
            fun.drawPlineOfw(dxf, xiline20, 1, contour);
            Vector2[] xiline21 = { p115, p116 };
            fun.drawPlineOfw(dxf, xiline21, 1, contour);
            Vector2[] xiline22 = { p651, p60, p59, p110 };
            fun.drawPlineOfw(dxf, xiline22, 1, contour);
            Vector2[] xiline23 = { p1171, p58, p57 };
            fun.drawPlineOfw(dxf, xiline23, 1, contour);
            Vector2[] xiline28 = { p1191, p56, p55, p121 };
            fun.drawPlineOfw(dxf, xiline28, 1, contour);
            Vector2[] xiline24 = { p53, p52, p51 };
            fun.drawPlineOfw(dxf, xiline24, 1, contour);
            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(p651));
            poly4.Vertexes.Add(new LwPolylineVertex(p108));
            poly4.Vertexes[1].Bulge = Math.Tan(pi / 10);
            poly4.Vertexes.Add(new LwPolylineVertex(p109));
            poly4.Vertexes.Add(new LwPolylineVertex(p110));
            fun.PolyFill(dxf, poly4, 0.3, contour);
            LwPolyline poly5 = new LwPolyline();
            poly5.Vertexes.Add(new LwPolylineVertex(p1171));
            poly5.Vertexes[0].Bulge = Math.Tan(pi / 10);
            poly5.Vertexes.Add(new LwPolylineVertex(p117));
            poly5.Vertexes.Add(new LwPolylineVertex(p118));
            poly5.Vertexes.Add(new LwPolylineVertex(p57));
            fun.PolyFill(dxf, poly5, 0.3, contour);
            LwPolyline poly6 = new LwPolyline();
            poly6.Vertexes.Add(new LwPolylineVertex(p1191));
            poly6.Vertexes.Add(new LwPolylineVertex(p119));
            poly6.Vertexes[1].Bulge = Math.Tan(pi / 10);
            poly6.Vertexes.Add(new LwPolylineVertex(p220));
            poly6.Vertexes.Add(new LwPolylineVertex(p121));
            fun.PolyFill(dxf, poly6, 0.3, contour);
            LwPolyline poly8 = new LwPolyline();
            poly8.Vertexes.Add(new LwPolylineVertex(p53));
            poly8.Vertexes.Add(new LwPolylineVertex(p123));
            poly8.Vertexes[1].Bulge = Math.Tan(pi / 10);
            poly8.Vertexes.Add(new LwPolylineVertex(p124));
            poly8.Vertexes.Add(new LwPolylineVertex(p51));
            fun.PolyFill(dxf, poly8, 0.3, contour);
            LwPolyline poly7 = new LwPolyline();
            poly7.Vertexes.Add(new LwPolylineVertex(p65));
            poly7.Vertexes[0].Bulge = Math.Tan(pi / 10);
            poly7.Vertexes.Add(new LwPolylineVertex(p80));
            poly7.Vertexes.Add(new LwPolylineVertex(p79));
            poly7.Vertexes.Add(new LwPolylineVertex(p78));
            poly7.Vertexes.Add(new LwPolylineVertex(p77));
            poly7.Vertexes.Add(new LwPolylineVertex(p76));
            poly7.Vertexes.Add(new LwPolylineVertex(p75));
            poly7.Vertexes.Add(new LwPolylineVertex(p74));
            poly7.Vertexes.Add(new LwPolylineVertex(p743));
            poly7.Vertexes.Add(new LwPolylineVertex(p742));
            poly7.Vertexes.Add(new LwPolylineVertex(p741));
            poly7.Vertexes.Add(new LwPolylineVertex(p740));
            fun.PolyFill(dxf, poly7, 0.3, contour);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(p73, p51), offset * 7.5 + p67.X - (p73.X + p51.X) / 2, 270, dimensionStyle);
            dim1.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(p67, p51), offset * 6 + (p67.X - p51.X) / 2, 270, dimensionStyle);
            dim2.UserText = "LPR = " + Math.Round(lpr / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(p32, p72), offset, 0, dimensionStyle);
            dim3.UserText = "DMM = " + Math.Round(dmm / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(p67, p73), offset * 6 + (p67.X - p73.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LS = " + Math.Round(ls / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            LinearDimension dim5 = new LinearDimension(new Line(p65, p51), offset * 5 + p67.X - (p65.X + p51.X) / 2, 270, dimensionStyle);
            dim5.UserText = "LU = " + Math.Round(lu / scale, 2);
            dxf.AddEntity(dim5);
            /*
            LinearDimension dim6 = new LinearDimension(new Line(p61, p51), offset * 3, 270, dimensionStyle);
            dim6.UserText = String.Format("{0}", l);
            dxf.AddEntity(dim6);
            */
            //尺寸7
            LinearDimension dim7 = new LinearDimension(new Line(p60, p51), offset * 3 + (p60.X - p51.X) / 2, 270, dimensionStyle);
            dim7.UserText = "SDN_4 = " + Math.Round(sdn_4 / scale, 2);
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(p51, p52), offset + p67.X - (p51.X + p52.X) / 2, 270, dimensionStyle);
            dim8.UserText = "PLGL = " + Math.Round(plgl / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(p55, p52), offset + p67.X - (p55.X + p52.X) / 2, 270, dimensionStyle);
            dim9.UserText = "SDL_1 = " + Math.Round(sdl_1 / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p20, p19), new Line(p60, p59), offset + dc_x / 2 / Math.Tan(sta_4 / 2), dimensionStyle);
            angdim1.UserText = "STA_4 = " + Math.Round(sta_4 / (pi / 180), 2) + "°";
            dxf.AddEntity(angdim1);
            //尺寸11
            Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(p00, p01), new Line(p51, p52), offset + p51.X / Math.Tan(plgang), dimensionStyle);
            angdim2.UserText = "PLGANG = " + Math.Round(plgang / (pi / 180), 2) + "°";
            dxf.AddEntity(angdim2);
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(p33, p12), -offset - (p33.X + p12.X) / 2 + p27.X, 270, dimensionStyle);
            dim11.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim11);
            //尺寸12
            LinearDimension dim12 = new LinearDimension(new Line(p12, p52), -offset - plgl, 0, dimensionStyle);
            dim12.UserText = "DC_1 = " + Math.Round(dc_1 / scale, 2);
            dxf.AddEntity(dim12);
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(p20, p60), -offset * 2 - p60.Y + p51.Y, 0, dimensionStyle);
            dim13.UserText = "DC_4 = " + Math.Round(dc_x / scale, 2);
            dxf.AddEntity(dim13);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 + oal / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void Bell_styleReamer312(Dictionary<string, Object> data)  //钟罩式铰刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            //作图
            //参数
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && soal < 67)
            {
                scale = 4.0;
            }
            else if (scale == 0 && soal < 90)
            {
                scale = 3.0;
            }
            else if (scale == 0 && soal < 134)
            {
                scale = 2.0;
            }
            else if (scale == 0 && soal < 178)
            {
                scale = 1.5;
            }
            else if (scale == 0 && soal < 268)
            {
                scale = 1.0;
            }
            else if (scale == 0 && soal < 357)
            {
                scale = 0.75;
            }
            else if (scale == 0)
            {
                scale = 0.5;
            }
            double pi = Math.PI;
            double dmm = Convert.ToDouble(data["dmm"]) * scale; //Convert.ToDouble(data["dmm"]);
            double oal = Convert.ToDouble(data["oal"]) * scale; //Convert.ToDouble(data["oal"]);
            double ls = Convert.ToDouble(data["ls"]) * scale; //Convert.ToDouble(data["ls"]);
            double lpr = oal - ls; //Convert.ToDouble(data["lpr"]);
            //double lu = 70 * scale; //Convert.ToDouble(data["lu"]);
            //double sd_2 = 35 * scale; //Convert.ToDouble(data["sd_2"]);
            double plgl = Convert.ToDouble(data["plgl"]) * scale; //Convert.ToDouble(data["plgl"]);
            double plgang = Convert.ToDouble(data["plgang"]) * pi / 180; //Convert.ToDouble(data["plgang"]);
            double dc_2 = Convert.ToDouble(data["dc2"]) * scale; //Convert.ToDouble(data["lu"]);
            double dc_1 = Convert.ToDouble(data["dc1"]) * scale; //Convert.ToDouble(data["lu"]);
            double sdl_1 = Convert.ToDouble(data["sdl1"]) * scale; //Convert.ToDouble(data["sdl_1"]);
            double bdx = Convert.ToDouble(data["bdx"]) * scale; //Convert.ToDouble(data["bdx"]);
            double lf = oal - plgl; //Convert.ToDouble(data["lf"]);
            double sta_2 = Convert.ToDouble(data["sta2"]) * pi / 180; //Convert.ToDouble(data["sta_2"]);
            double sdl_2 = Convert.ToDouble(data["sdl2"]) * scale; //Convert.ToDouble(data["sdl_2"]);
            //double sdl_3 = 25; //Convert.ToDouble(data["sdl_3"]);
            // double sd_3 = 70; //Convert.ToDouble(data["sd_3"]);
            string path = Convert.ToString(data["path"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            Vector2 p00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p01 = fun.Polar(p00, 0.5 * pi, oal);  // 基准点 角度（弧度制） 距离
            Vector2 p0 = fun.Polar(p01, 0, dmm / 2 - 1);
            Vector2 p50 = fun.Polar(p01, pi, dmm / 2 - 1);
            Vector2 p1 = new Vector2(p0.X + 1, p0.Y - 1);
            Vector2 p51 = new Vector2(p50.X - 1, p50.Y - 1);
            Vector2 p2 = new Vector2(p1.X, p0.Y - ls + 1);
            Vector2 p52 = new Vector2(p51.X, p0.Y - ls + 1);
            Vector2 p3 = new Vector2(p2.X - 1, p2.Y - 1);
            Vector2 p53 = new Vector2(p52.X + 1, p52.Y - 1);
            Vector2 p02 = new Vector2(p00.X, p01.Y - ls);
            Vector2 p4 = new Vector2(p02.X + 0.4 * bdx, p02.Y);
            Vector2 p54 = new Vector2(p02.X - 0.4 * bdx, p02.Y);
            Vector2 p8 = fun.Polar(p00, 0, bdx / 2);
            Vector2 p58 = fun.Polar(p00, pi, bdx / 2);
            Vector2 p10 = new Vector2(p8.X - bdx / 2 + dc_1 / 2, p8.Y + plgl);
            Vector2 p9 = fun.Polar(p10, 1.5 * pi + plgang, plgl / Math.Cos(plgang));
            Vector2 p11 = new Vector2(p10.X, p10.Y + sdl_1);
            Vector2 p12 = new Vector2(dc_2 / 2, p11.Y + (dc_1 - dc_2) / Math.Tan(sta_2 / 2));
            Vector2 p13 = new Vector2(p12.X, p12.Y + sdl_2);
            Vector2 p14 = fun.Polar(p13, plgang, plgl);
            Vector2 p15 = new Vector2(p14.X, p14.Y + plgl);
            Vector2 p16 = fun.Polar(p15, pi / 2 + plgang, plgl / 2);
            Vector2 p17 = new Vector2(p00.X, p16.Y);
            Vector2 p5 = new Vector2(p4.X, p4.Y - ls / 8);
            Vector2 p55 = new Vector2(p54.X, p4.Y - ls / 8);
            Vector2 p18 = new Vector2(p00.X, p5.Y - 2);
            Vector2 p19 = new Vector2(p02.X + 0.25 * bdx, p5.Y);
            Vector2 p20 = new Vector2(p19.X, p4.Y);
            Vector2 p21 = new Vector2(p02.X - 0.25 * bdx, p02.Y);
            Vector2 p22 = new Vector2(p02.X - 0.25 * bdx, p5.Y);
            Vector2 p6 = new Vector2(p8.X - 2, p5.Y);
            Vector2 p56 = new Vector2(p58.X + 2, p55.Y);
            Vector2 p7 = new Vector2(p6.X + 2, p6.Y - 2);
            Vector2 p57 = new Vector2(p56.X - 2, p6.Y - 2);
            Vector2 p03 = new Vector2(p02.X, p5.Y);
            //Vector2 p30 = new Vector2(p14.X, p8.Y + lu);
            Vector2 p46 = new Vector2(p10.X + 0.1 * bdx, p9.Y);
            Vector2 p43 = new Vector2(p10.X, p10.Y + sdl_1 * 0.7);
            Vector2 p45 = new Vector2(p43.X + 0.07 * bdx, p43.Y);
            Vector2 p44 = new Vector2(p45.X + 0.03 * bdx, p45.Y - sdl_1 * 0.2);
            Vector2 p42 = new Vector2(p12.X + 0.1 * bdx, p11.Y);
            Vector2 p39 = new Vector2(p12.X, p12.Y + sdl_1 * 0.7);
            Vector2 p40 = new Vector2(p39.X + 0.07 * bdx, p39.Y);
            Vector2 p41 = new Vector2(p40.X + 0.03 * bdx, p40.Y - sdl_1 * 0.2);
            Vector2 p37 = new Vector2(p17.X, p15.Y);
            Vector2 p171 = new Vector2((p17.X + p16.X) / 2, p17.Y);
            Vector2 p71 = new Vector2(p7.X, p7.Y - plgl);
            //线段
            Vector2[] Line1 = { p14, new Vector2(0, p14.Y) };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { p13, new Vector2(0, p13.Y) };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line3 = { p12, new Vector2(0, p12.Y) };
            fun.drawBLine(dxf, Line3, 0.3, contour);
            Vector2[] Line4 = { p11, new Vector2(0, p11.Y) };
            fun.drawBLine(dxf, Line4, 0.3, contour);
            Vector2[] Line5 = { p10, new Vector2(0, p10.Y) };
            fun.drawBLine(dxf, Line5, 0.3, contour);
            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p0));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p10));
            poly.Vertexes.Add(new LwPolylineVertex(p11));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p13));
            poly.Vertexes.Add(new LwPolylineVertex(p14));
            poly.Vertexes.Add(new LwPolylineVertex(p15));
            poly.Vertexes.Add(new LwPolylineVertex(p16));
            poly.Vertexes.Add(new LwPolylineVertex(p17));
            fun.PolyFill(dxf, poly, 0.3, contour);
            Vector2[] dotline1 = { fun.Polar(p01, pi / 2, 4), fun.Polar(p00, 1.5 * pi, 4) };
            fun.drawPlinetype(dxf, dotline1, 0.15, center, Linetype.Center);
            Vector2[] xiline1 = { p8, p58, p57, p56, p55, p54, p53, p52, p51, p50, p0 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, contour);
            Vector2[] xiline2 = { p51, p1 };
            fun.drawPlineOfw(dxf, xiline2, 0.3, contour);
            Vector2[] xiline3 = { p2, p52, };
            fun.drawPlineOfw(dxf, xiline3, 0.3, contour);
            Vector2[] xiline4 = { p3, p53 };
            fun.drawPlineOfw(dxf, xiline4, 0.3, contour);
            Vector2[] xiline5 = { p20, p19, p21, p22, p20 };
            fun.drawPlineOfw(dxf, xiline5, 0.3, contour);
            Vector2[] xiline6 = { p6, p56 };
            fun.drawPlineOfw(dxf, xiline6, 0.3, contour);
            Vector2[] xiline9 = { p18, p57 };
            fun.drawPlineOfw(dxf, xiline9, 0.3, contour);
            Vector2[] xiline10 = { p15, p37 };
            fun.drawPlineOfw(dxf, xiline10, 0.3, contour);
            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p71));
            poly3.Vertexes.Add(new LwPolylineVertex(p171));
            poly3.Vertexes.Add(new LwPolylineVertex(p17));
            poly3.Vertexes.Add(new LwPolylineVertex(p18));
            poly3.Vertexes.Add(new LwPolylineVertex(p7));
            poly3.Vertexes[0].Bulge = Math.Tan(pi / 10);
            poly3.IsClosed = true;
            poly3.SetConstantWidth(0.03);
            /*
            Vector2 coc1 = new Vector2((p17.X + p71.X) / 2, (p17.Y + p71.Y) / 2);
            Arc arc1 = fun.DrawArc(p17, coc1, p71);
            arc1.Layer = contour;
            dxf.AddEntity(arc1);
            */
            String[] type = new String[100];
            Line[] line = new Line[100];
            Arc[] arc2 = new Arc[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
                if (type[i] == "Arc")
                {
                    arc2[i] = (Arc)poly3.Explode()[i];
                }
            }
            //fun.hatchsubofline(dxf, type, numst, 5, 12, line, hatching);  //  dxf type numst 填充线段的间距 填充线段的角度 line 图层颜色
            fun.hatchsub1(dxf, type, numst, 20, 15, line, arc2, hatching);
            fun.PolyFill(dxf, poly3, 0.3, contour);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(p0, p8), offset * 3 + (p8.X - p0.X) / 2, 270, dimensionStyle);
            dim1.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(p4, p8), offset * 2 + (p8.X - p4.X) / 2, 270, dimensionStyle);
            dim2.UserText = "LPR = " + Math.Round(lpr / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(p51, p1), offset + p0.Y - p1.Y, 0, dimensionStyle);
            dim3.UserText = "DMM = " + Math.Round(dmm / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(p0, p4), offset * 2 + p8.X - (p4.X + p0.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LS = " + Math.Round(ls / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(p10, p8), offset + (p8.X - p10.X) / 2, 270, dimensionStyle);
            dim6.UserText = "PLGL = " + Math.Round(plgl / scale, 2);
            dxf.AddEntity(dim6);
            /*
            LinearDimension dim7 = new LinearDimension(new Line(p00, p14), offset * 5, 180, dimensionStyle);
            //dim7.SetDimensionLinePosition(new Vector2(p30.X - 10, p30.Y-10));
            //fun.dxflinedim(dxf, dim7, dcn );
            dim7.UserText = String.Format("{0}", dc_2);
            dxf.AddEntity(dim7);
            */
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(new Vector2(-p12.X, p12.Y), p12), -offset * 2 - p12.Y + p8.Y, 0, dimensionStyle);
            dim8.UserText = "DC_2 = " + Math.Round(dc_2 / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(new Vector2(-p10.X, p10.Y), p10), -offset * 3 - p10.Y + p00.Y, 0, dimensionStyle);
            dim9.UserText = "DC_1 = " + Math.Round(dc_1 / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(new Vector2(p00.X, p10.Y), p00), new Line(p10, p9), offset + p10.X / Math.Tan(plgang), dimensionStyle);
            angdim1.UserText = "PLGANG = " + Math.Round(plgang / (pi / 180), 2) + "°";
            dxf.AddEntity(angdim1);
            //尺寸7
            Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(new Vector2(-p12.X, p12.Y), new Vector2(-p11.X, p11.Y)), new Line(p12, p11), offset + p11.X / Math.Tan(sta_2 / 2), dimensionStyle);
            angdim2.UserText = "STA_2 = " + Math.Round(sta_2 / (pi / 180), 2) + "°";
            dxf.AddEntity(angdim2);
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(p50, p10), -offset - (p50.X + p10.X) / 2 + p58.X, 270, dimensionStyle);
            dim11.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim11);
            //尺寸12
            LinearDimension dim12 = new LinearDimension(new Line(p10, p11), offset + p8.X - p10.X, 270, dimensionStyle);
            dim12.UserText = "SDL_1 = " + Math.Round(sdl_1 / scale, 2);
            dxf.AddEntity(dim12);
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(p12, p13), offset + p8.X - p13.X, 270, dimensionStyle);
            dim13.UserText = "SDL_2 = " + Math.Round(sdl_2 / scale, 2);
            dxf.AddEntity(dim13);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 + oal / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void ShellReamer312(Dictionary<string, Object> data)  //套式铰刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            //作图
            //参数
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && soal < 67)
            {
                scale = 4.0;
            }
            else if (scale == 0 && soal < 90)
            {
                scale = 3.0;
            }
            else if (scale == 0 && soal < 134)
            {
                scale = 2.0;
            }
            else if (scale == 0 && soal < 178)
            {
                scale = 1.5;
            }
            else if (scale == 0 && soal < 268)
            {
                scale = 1.0;
            }
            else if (scale == 0 && soal < 357)
            {
                scale = 0.75;
            }
            else if (scale == 0)
            {
                scale = 0.5;
            }
            double pi = Math.PI;
            double df = Convert.ToDouble(data["df"]) * scale; //Convert.ToDouble(data["df"]);
            double dc = Convert.ToDouble(data["dc"]) * scale; //Convert.ToDouble(data["dc"]);
            double apmx = Convert.ToDouble(data["apmx"]) * scale; //Convert.ToDouble(data["l"]);
            double oal = Convert.ToDouble(data["oal"]) * scale; //Convert.ToDouble(data["oal"]);
            double dmm = Convert.ToDouble(data["dmm"]) * scale; //Convert.ToDouble(data["czcms"]);
            double plgl = Convert.ToDouble(data["plgl"]) * scale; //Convert.ToDouble(data["plgl"]);
            double plgang = Convert.ToDouble(data["plgang"]) * pi / 180; //Convert.ToDouble(data["plgang"]);
            double lf = oal - plgl; //Convert.ToDouble(data["lf"]);
            string path = Convert.ToString(data["path"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            Vector2 p00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 p01 = fun.Polar(p00, 0.5 * pi, oal);  // 基准点 角度（弧度制） 距离      
            Vector2 p5 = fun.Polar(p00, 0, df / 2);
            Vector2 p4 = new Vector2(p00.X + dc / 2, p00.Y + plgl);
            Vector2 p3 = new Vector2(p4.X, p4.Y + apmx - plgl);
            Vector2 p1 = new Vector2(p5.X, p5.Y + oal);
            Vector2 p19 = new Vector2(p1.X - (0.9 * df - dmm), p1.Y);
            Vector2 p2 = new Vector2(p5.X, p3.Y + plgl);
            Vector2 p18 = new Vector2(p19.X, p2.Y + 3);
            Vector2 p17 = new Vector2(p18.X - 0.03 * dmm, p18.Y);
            Vector2 p16 = new Vector2(p00.X, p17.Y);
            Vector2 p15 = new Vector2(p00.X - df / 2, p1.Y);
            Vector2 p9 = new Vector2(p00.X - dc / 2, p4.Y);
            Vector2 p12 = new Vector2(p9.X, p00.Y + apmx);
            Vector2 p14 = new Vector2(p15.X, p16.Y);
            Vector2 p13 = new Vector2(p14.X, p14.Y - plgl / 2);
            Vector2 p11 = new Vector2(p12.X + plgl / 2, p12.Y);
            Vector2 p10 = new Vector2(p9.X + plgl / 2, p9.Y);
            Vector2 p8 = new Vector2(p9.X + 0.5 * plgl / Math.Tan(plgang), p00.Y);
            Vector2 p7 = new Vector2(p8.X + plgl / 2, p8.Y);
            Vector2 p6 = new Vector2(p17.X - p17.Y / 60, p00.Y);
            Vector2 p31 = new Vector2(p00.X + df / 6, p1.Y);
            Vector2 p32 = new Vector2(p31.X - df / 15, p31.Y - df / 15);
            Vector2 p33 = new Vector2(p32.X, p32.Y - df / 8);
            Vector2 p34 = new Vector2(p33.X - df / 15, p33.Y - df / 15);
            Vector2 p38 = new Vector2(p00.X - df / 6, p1.Y);
            Vector2 p37 = new Vector2(p38.X + df / 15, p32.Y);
            Vector2 p36 = new Vector2(p37.X, p32.Y - df / 8);
            Vector2 p35 = new Vector2(p36.X + df / 15, p36.Y - df / 15);
            Vector2 p50 = new Vector2(p5.X + 0.2 * plgl / Math.Tan(plgang), p5.Y + apmx / 3);
            Vector2 p55 = new Vector2(p5.X, p50.Y + apmx / 9 - Math.Sqrt(apmx * apmx / 81 - (p50.X - p5.X) * (p50.X - p5.X)));
            Vector2 p51 = new Vector2(p50.X, p50.Y + apmx / 3);
            Vector2 p52 = new Vector2(p55.X, p51.Y - p55.Y + p50.Y);
            Vector2 p53 = new Vector2(p51.X - apmx / 9, p51.Y - apmx / 9);
            Vector2 p54 = new Vector2(p53.X, p50.Y + apmx / 9);
            Vector2 p56 = new Vector2(p5.X - 0.6 * plgl / Math.Tan(plgang), p5.Y);
            Vector2 p59 = new Vector2(p5.X, p5.Y + apmx);
            Vector2 p58 = new Vector2(p59.X - 0.4 * plgl / Math.Tan(plgang), p59.Y);
            Vector2 p57 = new Vector2(p59.X - 0.6 * plgl / Math.Tan(plgang), p59.Y - 0.2 * plgl / Math.Tan(plgang));
            //线段
            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p14));
            poly.Vertexes.Add(new LwPolylineVertex(p15));
            poly.Vertexes.Add(new LwPolylineVertex(p38));
            poly.Vertexes[12].Bulge = Math.Tan(pi / (-8));
            poly.Vertexes.Add(new LwPolylineVertex(p37));
            poly.Vertexes.Add(new LwPolylineVertex(p36));
            poly.Vertexes[14].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p35));
            poly.Vertexes.Add(new LwPolylineVertex(p34));
            poly.Vertexes[16].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p33));
            poly.Vertexes.Add(new LwPolylineVertex(p32));
            poly.Vertexes[18].Bulge = Math.Tan(pi / (-8));
            poly.Vertexes.Add(new LwPolylineVertex(p31));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);
            Vector2[] Line1 = { p1, p52 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { p53, p54 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            LwPolyline Arc3 = new LwPolyline();
            Arc3.Vertexes.Add(new LwPolylineVertex(p51));
            Arc3.Vertexes.Add(new LwPolylineVertex(p53));
            Arc3.Vertexes[0].Bulge = (1 - Math.Cos(pi / 4)) * Math.Cos(pi / 4) * 2;
            fun.PolyFill(dxf, Arc3, 0.3, contour);
            LwPolyline Arc4 = new LwPolyline();
            Arc4.Vertexes.Add(new LwPolylineVertex(p54));
            Arc4.Vertexes.Add(new LwPolylineVertex(p50));
            Arc4.Vertexes[0].Bulge = (1 - Math.Cos(pi / 4)) * Math.Cos(pi / 4) * 2;
            fun.PolyFill(dxf, Arc4, 0.3, contour);
            Vector2[] dotline1 = { fun.Polar(p01, pi / 2, 4), fun.Polar(p00, 1.5 * pi, 4) };
            fun.drawPlinetype(dxf, dotline1, 0.15, center, Linetype.Center);
            Vector2[] xiline1 = { p7, p10, p11, p13, p14 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, contour);
            Vector2[] xiline2 = { p5, p55 };
            fun.drawPlineOfw(dxf, xiline2, 0.3, contour);
            Vector2[] xiline3 = { p2, p1, p19, p18, p17, p6 };
            fun.drawPlineOfw(dxf, xiline3, 0.3, contour);
            Vector2[] xiline4 = { p16, p17 };
            fun.drawPlineOfw(dxf, xiline4, 0.3, contour);
            //填充1
            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p1));
            poly3.Vertexes.Add(new LwPolylineVertex(p2));
            poly3.Vertexes.Add(new LwPolylineVertex(p59));
            poly3.Vertexes.Add(new LwPolylineVertex(p58));
            poly3.Vertexes[3].Bulge = Math.Tan(pi / (8));
            poly3.Vertexes.Add(new LwPolylineVertex(p57));
            poly3.Vertexes.Add(new LwPolylineVertex(p56));
            poly3.Vertexes.Add(new LwPolylineVertex(p6));
            poly3.Vertexes.Add(new LwPolylineVertex(p17));
            poly3.Vertexes.Add(new LwPolylineVertex(p18));
            poly3.Vertexes.Add(new LwPolylineVertex(p19));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;
            String[] type = new String[100];
            Line[] line = new Line[100];
            Arc[] arc2 = new Arc[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
                if (type[i] == "Arc")
                {
                    arc2[i] = (Arc)poly3.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, type, numst, 20, 15, line, arc2, hatching);
            fun.PolyFill(dxf, poly3, 0.3, contour);
            Vector2[] Line3 = { p50, p51 };
            fun.drawBLine(dxf, Line3, 0.3, contour);
            //填充2
            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(p4));
            poly4.Vertexes.Add(new LwPolylineVertex(p3));
            poly4.Vertexes.Add(new LwPolylineVertex(p2));
            poly4.Vertexes.Add(new LwPolylineVertex(p52));
            poly4.Vertexes[3].Bulge = -Math.Tan(Math.Asin((p51.X - p52.X) * 9 / apmx) / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(p51));
            poly4.Vertexes.Add(new LwPolylineVertex(p50));
            poly4.Vertexes[5].Bulge = -Math.Tan(Math.Asin((p51.X - p52.X) * 9 / apmx) / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(p55));
            poly4.Vertexes.Add(new LwPolylineVertex(p5));
            poly4.SetConstantWidth(0.3);
            poly4.IsClosed = true;
            String[] type3 = new String[100];
            Line[] line3 = new Line[100];
            Arc[] arc3 = new Arc[100];
            int numst1 = poly4.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst1; i++)
            {
                type3[i] = poly4.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type3[i] == "Line")
                {
                    line3[i] = (Line)poly4.Explode()[i];
                }
                if (type3[i] == "Arc")
                {
                    arc3[i] = (Arc)poly4.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, type3, numst1, 20, 12, line3, arc3, hatching);
            fun.PolyFill(dxf, poly4, 0.3, contour);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(p1, p5), offset * 5 + p3.X - p1.X, 270, dimensionStyle);
            dim1.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(p3, p5), offset * 3.5 + (p3.X - p5.X) / 2, 270, dimensionStyle);
            dim2.UserText = "APMX = " + Math.Round(apmx / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(p15, p1), offset * 2, 0, dimensionStyle);
            dim3.UserText = "DF = " + Math.Round(df / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(p5, p4), offset*2 + (p4.X - p5.X) / 2, 270, dimensionStyle);
            dim4.UserText = "PLGL = " + Math.Round(plgl / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            LinearDimension dim5 = new LinearDimension(new Line(p8, p4), offset * 3, 180, dimensionStyle);
            dim5.UserText = "DC = " + Math.Round(dc / scale, 2); 
            dxf.AddEntity(dim5);
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(p10, p15), -offset - (p10.X + p15.X) / 2 + p9.X, 270, dimensionStyle);
            dim6.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(p5, new Vector2(p5.X, p4.Y)), new Line(p5, p4), offset + plgl, dimensionStyle);
            angdim1.UserText = "PLGANG = " + Math.Round(plgang / (pi / 180), 2) + "°";
            dxf.AddEntity(angdim1);
            //尺寸8
            LinearDimension dim11 = new LinearDimension(new Line(new Vector2(-p17.X, p17.Y), p17), offset + p1.Y - p17.Y, 0, dimensionStyle);
            dim11.UserText = "DMM = " + Math.Round(dmm / scale, 2);
            dxf.AddEntity(dim11);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 200 + oal / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

    }
}
